﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web; 
using System.Text;
using System.Data;

namespace ZHDJ.MobileInterface
{
//    [SXT.Data.DBTable("tblPartyATMSaveThings", DBName = "SXT.DefaultDBEx")]
//    public class PartyATMSaveThings : SXT.Data.DataModel
//    {
//        #region 字段属性
//        /// <summary>
//        /// 
//        /// </summary>
//        [SXT.Data.DBField(IsPrimaryKey = true)]
//        public string ID { get; set; }

//        /// <summary>
//        /// 
//        /// </summary>
//        [SXT.Data.DBField]
//        public string Name { get; set; }

//        /// <summary>
//        /// 
//        /// </summary>
//        [SXT.Data.DBField]
//        public string Titular { get; set; }

//        /// <summary>
//        /// 
//        /// </summary>
//        [SXT.Data.DBField]
//        public string ThingType { get; set; }

//        /// <summary>
//        /// 
//        /// </summary>
//        [SXT.Data.DBField]
//        public int ThingCount { get; set; }

//        /// <summary>
//        /// 
//        /// </summary>
//        [SXT.Data.DBField]
//        public string Description { get; set; }

//        /// <summary>
//        /// 
//        /// </summary>
//        [SXT.Data.DBField]
//        public bool? IsEndTime { get; set; }

//        /// <summary>
//        /// 
//        /// </summary>
//        [SXT.Data.DBField]
//        public DateTime? EndTime { get; set; }

//        /// <summary>
//        /// 
//        /// </summary>
//        [SXT.Data.DBField]
//        public string Purposes { get; set; }

//        /// <summary>
//        /// 
//        /// </summary>
//        [SXT.Data.DBField]
//        public string PurposesDescription { get; set; }

//        /// <summary>
//        /// 
//        /// </summary>
//        [SXT.Data.DBField]
//        public string SaveModus { get; set; }

//        /// <summary>
//        /// 
//        /// </summary>
//        [SXT.Data.DBField]
//        public string Createby { get; set; }

//        /// <summary>
//        /// 
//        /// </summary>
//        [SXT.Data.DBField]
//        public string CreatebyAddress { get; set; }

//        /// <summary>
//        /// 
//        /// </summary>
//        [SXT.Data.DBField]
//        public string CreatebyContact { get; set; }

//        /// <summary>
//        /// 
//        /// </summary>
//        [SXT.Data.DBField]
//        public string BranchID { get; set; }

//        /// <summary>
//        /// 
//        /// </summary>
//        [SXT.Data.DBField]
//        public string BranchName { get; set; }

//        /// <summary>
//        /// 
//        /// </summary>
//        [SXT.Data.DBField]
//        public string BranchAddress { get; set; }

//        /// <summary>
//        /// 
//        /// </summary>
//        [SXT.Data.DBField]
//        public string BranchContactPerson { get; set; }

//        /// <summary>
//        /// 
//        /// </summary>
//        [SXT.Data.DBField]
//        public string BranchContact { get; set; }

//        /// <summary>
//        /// 
//        /// </summary>
//        [SXT.Data.DBField]
//        public DateTime? CreateTime { get; set; }

//        /// <summary>
//        /// 
//        /// </summary>
//        [SXT.Data.DBField]
//        public string ModifyBy { get; set; }

//        /// <summary>
//        /// 
//        /// </summary>
//        [SXT.Data.DBField]
//        public DateTime? ModifyTime { get; set; }

//        /// <summary>
//        /// 
//        /// </summary>
//        [SXT.Data.DBField]
//        public bool? IsSub { get; set; }

//        /// <summary>
//        /// 
//        /// </summary>
//        [SXT.Data.DBField]
//        public string Status { get; set; }

//        /// <summary>
//        /// 
//        /// </summary>
//        [SXT.Data.DBField]
//        public string IsLoveActivity { get; set; }


//        [DBField]
//        public string SignX { get; set; }

//        [DBField]
//        public string SignY { get; set; }

//        [DBField]
//        public string SignZ { get; set; }
//        #endregion

//        #region 扩展属性


//        #endregion

//        #region 数据操作方法
//        public static System.Data.DataSet GetGridData(string name, string createBy, string branchID, string titular,
//            string thingType, string purposes, string saveModus, string status, string IsLoveActivity = "0")
//        {
//            using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand())
//            {
//                StringBuilder sbSql = new StringBuilder();
//                sbSql.Append(@"SELECT Data.*,
//ST.ParaMemberName as TitularName,STC.ParaMemberName as ThingTypeName,
//(CASE data.IsEndTime WHEN 1 THEN '是' ELSE '否' END) as IsEndTimeName,
//(CASE data.Purposes WHEN 2 THEN Data.PurposesDescription ELSE SP.ParaMemberName END) as PurposesName,
//SSM.ParaMemberName as SaveModusName,
//OM.UserName as CreateByName,OB.BranchName as CreateByBranchName,
//(CASE data.IsSub WHEN 1 THEN '是' ELSE '否' END) as IsSubName,
//SS.ParaMemberName as StatusName 
//FROM tblPartyATMSaveThings Data
//left join tblPartyOrgMembers OM on OM.LoginID = Data.CreateBy
//left join tblPartyOrgBranch OB on OB.BranchID = Data.BranchID and OB.BranchID =OM.BranchID
//left join tblSysSystemParameter ST on ST.ParaMember = Data.Titular and ST.ParaType = 'SXT.ATM.Titular'
//left join tblSysSystemParameter STC on STC.ParaMember = Data.ThingType and STC.ParaType = 'SXT.ATM.ThingType'
//left join tblSysSystemParameter SP on SP.ParaMember = Data.Purposes and SP.ParaType = 'SXT.ATM.Purposes'
//left join tblSysSystemParameter SSM on SSM.ParaMember = Data.SaveModus and SSM.ParaType = 'SXT.ATM.SaveModus'
//left join tblSysSystemParameter SS on SS.ParaMember = Data.Status and SS.ParaType = 'SXT.ATM.SaveStatus'
//where 1 = 1  ");

//                if (IsLoveActivity.Equals("1"))
//                {
//                    sbSql.Append(" and Data.IsLoveActivity = 1 ");
//                }
//                else
//                {
//                    sbSql.Append(" and (Data.IsLoveActivity = 0 or Data.IsLoveActivity is null) ");
//                }
//                if (!string.IsNullOrEmpty(name))
//                {
//                    sbSql.Append(" and Data.Name like @Name ");
//                    cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = string.Format("%{0}%", name);
//                }

//                if (!string.IsNullOrEmpty(branchID))
//                {
//                    sbSql.Append(" and Data.BranchID in (select ID from f_BranchID(dbo.QUERY_SECOND_GRADE_BRANCH(@BranchID)))  ");
//                    cmd.Parameters.Add("@BranchID", SqlDbType.VarChar).Value = string.Format("{0}", branchID);
//                }
//                else
//                {
//                    if (!string.IsNullOrEmpty(createBy))
//                    {
//                        sbSql.Append(" and Data.CreateBy = @CreateBy ");
//                        cmd.Parameters.Add("@CreateBy", SqlDbType.VarChar).Value = string.Format("{0}", createBy);
//                    }
//                }
//                if (!string.IsNullOrEmpty(titular))
//                {
//                    sbSql.Append(" and Data.Titular = @Titular ");
//                    cmd.Parameters.Add("@Titular", SqlDbType.VarChar).Value = string.Format("{0}", titular);
//                }
//                if (!string.IsNullOrEmpty(thingType))
//                {
//                    sbSql.Append(" and Data.ThingType = @ThingType ");
//                    cmd.Parameters.Add("@ThingType", SqlDbType.VarChar).Value = string.Format("{0}", thingType);
//                }
//                if (!string.IsNullOrEmpty(purposes))
//                {
//                    sbSql.Append(" and Data.Purposes = @Purposes ");
//                    cmd.Parameters.Add("@Purposes", SqlDbType.VarChar).Value = string.Format("{0}", purposes);
//                }
//                if (!string.IsNullOrEmpty(saveModus))
//                {
//                    sbSql.Append(" and Data.SaveModus = @SaveModus ");
//                    cmd.Parameters.Add("@SaveModus", SqlDbType.VarChar).Value = string.Format("{0}", saveModus);
//                }
//                if (!string.IsNullOrEmpty(status))
//                {
//                    sbSql.Append(" and Data.Status = @Status ");
//                    cmd.Parameters.Add("@Status", SqlDbType.VarChar).Value = string.Format("{0}", status);
//                }
//                sbSql.Append(" ORDER BY Data.Status,Data.EndTime DESC,Data.Name ");
//                cmd.CommandText = sbSql.ToString();
//                return SXT.DB.DBManager.DBSettings["SXT.DefaultDBEx"].ExecuteDataSet(cmd);
//            }
//        }

//        public static DataSet MatchSaveThings(string saveID, string status, string IsLoveActivity = "0")
//        {
//            using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand())
//            {
//                StringBuilder sbSql = new StringBuilder();
//                sbSql.Append(@"SELECT Data.*,
//ST.ParaMemberName as TitularName,STC.ParaMemberName as ThingTypeName,
//(CASE data.IsEndTime WHEN 1 THEN '是' ELSE '否' END) as IsEndTimeName,
//(CASE data.Purposes WHEN 2 THEN Data.PurposesDescription ELSE SP.ParaMemberName END) as PurposesName,
//SSM.ParaMemberName as SaveModusName,
//OM.UserName as CreateByName,OB.BranchName as CreateByBranchName,
//(CASE data.IsSub WHEN 1 THEN '是' ELSE '否' END) as IsSubName,
//SS.ParaMemberName as StatusName 
//FROM tblPartyATMSaveThings Data
//left join tblPartyOrgMembers OM on OM.LoginID = Data.CreateBy
//left join tblPartyOrgBranch OB on OB.BranchID = Data.BranchID and OB.BranchID =OM.BranchID
//left join tblSysSystemParameter ST on ST.ParaMember = Data.Titular and ST.ParaType = 'SXT.ATM.Titular'
//left join tblSysSystemParameter STC on STC.ParaMember = Data.ThingType and STC.ParaType = 'SXT.ATM.ThingType'
//left join tblSysSystemParameter SP on SP.ParaMember = Data.Purposes and SP.ParaType = 'SXT.ATM.Purposes'
//left join tblSysSystemParameter SSM on SSM.ParaMember = Data.SaveModus and SSM.ParaType = 'SXT.ATM.SaveModus'
//left join tblSysSystemParameter SS on SS.ParaMember = Data.Status and SS.ParaType = 'SXT.ATM.SaveStatus'
//where 1 = 1  ");

//                if (string.IsNullOrEmpty(saveID))
//                {
//                    sbSql.Append(" and 1 = 2 ");
//                }
//                else
//                {
//                    PartyATMTakeThings sModel = new PartyATMTakeThings();
//                    sModel.ID = saveID;
//                    sModel.Load();
//                    if (IsLoveActivity.Equals("1"))
//                    {
//                        sbSql.Append(" and Data.ThingType = @ThingType ");
//                        cmd.Parameters.Add("@ThingType", SqlDbType.VarChar).Value = string.Format("{0}", sModel.ThingType);
//                        sbSql.Append(" and Data.EndTime >= @EndTime and (Status = '0' or Data.ID in (select SaveID from tblPartyATMSaveAndTake where TakeID = @ID )) and Data.BranchID in (select ID from f_BranchID(dbo.QUERY_SECOND_GRADE_BRANCH(@BranchID))) ");
//                        cmd.Parameters.Add("@EndTime", SqlDbType.VarChar).Value = string.Format("{0}", DateTime.Now.ToString("yyyy-MM-dd"));
//                        cmd.Parameters.Add("@ID", SqlDbType.VarChar).Value = string.Format("{0}", sModel.ID);
//                        cmd.Parameters.Add("@BranchID", SqlDbType.VarChar).Value = string.Format("{0}", sModel.BranchID);
//                    }
//                    else
//                    {
//                        if (status.Equals("0"))
//                        {
//                            if ((Convert.ToDateTime(sModel.EndTime) - DateTime.Now).Days >= 0)
//                            {
//                                if (!string.IsNullOrEmpty(sModel.Name))
//                                {
//                                    if (!string.IsNullOrEmpty(sModel.Name))
//                                    {
//                                        sbSql.Append(" and (Data.Name like @Name or @Name2 like '%'+Data.Name+'%') ");
//                                        cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = string.Format("%{0}%", sModel.Name);
//                                        cmd.Parameters.Add("@Name2", SqlDbType.VarChar).Value = string.Format("{0}", sModel.Name);
//                                    }
//                                    sbSql.Append(" and Data.EndTime >= @EndTime and Status = '0' and Data.BranchID in (select ID from f_BranchID(dbo.QUERY_SECOND_GRADE_BRANCH(@BranchID)))  ");
//                                    cmd.Parameters.Add("@EndTime", SqlDbType.VarChar).Value = string.Format("{0}", DateTime.Now.ToString("yyyy-MM-dd"));
//                                    cmd.Parameters.Add("@BranchID", SqlDbType.VarChar).Value = string.Format("{0}", sModel.BranchID);
//                                }
//                            }
//                            else
//                            {
//                                sbSql.Append(" and 1 = 2 ");
//                            }
//                        }
//                        else
//                        {
//                                sbSql.Append(" and Data.ID in (select SaveID from tblPartyATMSaveAndTake where TakeID = @ID )  and Status = @Status ");
//                                cmd.Parameters.Add("@ID", SqlDbType.VarChar).Value = string.Format("{0}", saveID);
//                                cmd.Parameters.Add("@Status", SqlDbType.VarChar).Value = string.Format("{0}", status);
//                        }
//                    }
//                }
//                sbSql.Append("  ORDER BY Data.Status,Data.EndTime DESC,Data.Name ");
//                cmd.CommandText = sbSql.ToString();
//                return SXT.DB.DBManager.DBSettings["SXT.DefaultDBEx"].ExecuteDataSet(cmd);
//            }
//        }

//        public static DataTable GetSaveThingsInfo(string ID)
//        {
//            using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand())
//            {
//                StringBuilder sbSql = new StringBuilder();
//                sbSql.Append(@"SELECT Data.*,
//ST.ParaMemberName as TitularName,STC.ParaMemberName as ThingTypeName,
//(CASE data.IsEndTime WHEN 1 THEN '是' ELSE '否' END) as IsEndTimeName,
//(CASE data.Purposes WHEN 2 THEN Data.PurposesDescription ELSE SP.ParaMemberName END) as PurposesName,
//SSM.ParaMemberName as SaveModusName,
//OM.UserName as CreateByName,OB.BranchName as CreateByBranchName,
//(CASE data.IsSub WHEN 1 THEN '是' ELSE '否' END) as IsSubName,
//SS.ParaMemberName as StatusName 
//FROM tblPartyATMSaveThings Data
//left join tblPartyOrgMembers OM on OM.LoginID = Data.CreateBy
//left join tblPartyOrgBranch OB on OB.BranchID = Data.BranchID and OB.BranchID =OM.BranchID
//left join tblSysSystemParameter ST on ST.ParaMember = Data.Titular and ST.ParaType = 'SXT.ATM.Titular'
//left join tblSysSystemParameter STC on STC.ParaMember = Data.ThingType and STC.ParaType = 'SXT.ATM.ThingType'
//left join tblSysSystemParameter SP on SP.ParaMember = Data.Purposes and SP.ParaType = 'SXT.ATM.Purposes'
//left join tblSysSystemParameter SSM on SSM.ParaMember = Data.SaveModus and SSM.ParaType = 'SXT.ATM.SaveModus'
//left join tblSysSystemParameter SS on SS.ParaMember = Data.Status and SS.ParaType = 'SXT.ATM.SaveStatus'
//where 1 = 1  and ID = @ID ");
//                cmd.Parameters.Add("@ID", SqlDbType.VarChar).Value = string.Format("{0}", ID);
//                cmd.CommandText = sbSql.ToString();
//                return SXT.DB.DBManager.DBSettings["SXT.DefaultDBEx"].ExecuteDataSet(cmd).Tables[0];
//            }
//        }
//        #endregion
//    }
}